package com.zhenzhen.xszhcp.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhenzhen.xszhcp.model.*;
import com.zhenzhen.xszhcp.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.util.*;

@RestController
public class selectController {
    @Autowired
    private GroupinfoService groupinfoService;
    @Autowired
    private MenuService menuService;
    @Autowired
    private LogService logService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private ClassesService classesService;
    @Autowired
    private KechengService kechengService;
    @Autowired
    private SemesterService semesterService;
    @Autowired
    private ZhuangtaiService zhuangtaiService;
    @Autowired
    private ActivityService activityService;
    @Autowired
    private GradeService gradeService;
    @Autowired
    private ZhcjService zhcjService;
    @Autowired
    private KcblService kcblService;

    /*用户组权限查询*/
    @RequestMapping("/selectyhzqxgl")
    public JSONObject selectyhzqxgl(HttpServletRequest httpServletRequest) {
        Map paramMap = new HashMap();
        List<Groupinfo> groupinfos = groupinfoService.getGroupinfoList(paramMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (groupinfos != null) {
            for (Groupinfo groupinfo : groupinfos) {
                int id = groupinfo.getId();
                String qx = groupinfo.getQx();
                String groupname = groupinfo.getGroupname();
                String qxs[] ={};
                Map map = new HashMap();
                //管理员、教师、学生
                map.put("id", id+"_a");
                map.put("field", id+"_a");
                map.put("title", groupname);
                if (qx!=null)
                    qxs = qx.split(",");
                Map child = selectfcd(httpServletRequest);
                List childdatas = (List) child.get("data");
                List childsmap = new ArrayList();
                for (int i = 0 ;i<childdatas.size();i++){
                    boolean sfxz = false;
                    Map childmap = (Map)childdatas.get(i);
                    int childid = Integer.parseInt(String.valueOf(childmap.get("id")));
                    String aaaa= Arrays.toString(qxs);
                    if (aaaa.length()>2&&qxs!=null) {
                        for (String qxbsstr : qxs) {
                            if (Integer.parseInt(qxbsstr) == childid) {
                                sfxz = true;
                                break;
                            }
                        }
                    }
                    //信息管理、成绩管理等父菜单
                    String childmenuname = String.valueOf(childmap.get("menuname"));
                    childmap.put("id",childid+"_b_"+id);
                    childmap.put("title",childmenuname);
                    childmap.put("checked",sfxz);
                    childmap.put("field",childid+"_b_"+id);
                    childsmap.add(childmap);
                }
                map.put("children",childsmap);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了全部权限节点数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询用户账号*/
    @RequestMapping("/selectyhz")
    public JSONObject selectyhz(HttpServletRequest httpServletRequest) {
        Map paramMap = new HashMap();
        List<Groupinfo> groupinfos = groupinfoService.getGroupinfoList(paramMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (groupinfos != null) {
            for (Groupinfo groupinfo : groupinfos) {
                int id = groupinfo.getId();
                String gstr = groupinfo.getGroupname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("gstr", gstr);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了用户组列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询所有父菜单*/
    @RequestMapping("/selectfcd")
    public Map<String, Object> selectfcd(HttpServletRequest httpServletRequest) {
        List<Menu> menus = menuService.getfdmmenuList();
        List<Map<String, Object>> list = new ArrayList<>();
        if (menus != null) {
            for (Menu menu : menus) {
                int id = menu.getId();
                String menuname = menu.getMenuname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("menuname", menuname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了父菜单信息数据",logService);
        return map1;
    }

    /*管理员查看教师信息*/
    @RequestMapping("/selectjsxxgl")
    public JSONObject selectjsxxgl(@RequestParam(required = false)String tname,@RequestParam(required = false) String tcard, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (tname!=null&&!tname.equals(""))
            requestparamMap.put("tname","%"+tname+"%");
        if (tcard!=null&&!tcard.equals(""))
            requestparamMap.put("tcard","%"+tcard+"%");
        List<Teacher> teachers = teacherService.getTeacherList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (teachers != null) {
            for (Teacher teacher : teachers) {
                int id = teacher.getId();
                String tnamestr = teacher.getTname();
                String tsex = teacher.getTsex();
                Date date = teacher.getTbirth();
                String tbirth = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日";
                int tcardstr = teacher.getTcard();
                String tphone = teacher.getTphone();
                String tzc = teacher.getTzc();
                Map map = new HashMap();
                map.put("id", id);
                map.put("tname", tnamestr);
                map.put("tsex", tsex);
                map.put("tbirth", tbirth);
                map.put("tcard", tcardstr);
                map.put("tphone", tphone);
                map.put("tzc", tzc);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了教师信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询活动信息*/
    @RequestMapping("/selecthdjlgl")
    public JSONObject selecthdjlgl(@RequestParam(required = false)String aname, HttpServletRequest httpServletRequest,@RequestParam int limit,@RequestParam int page) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Integer> stulist = new ArrayList<>();
        page = page-1;
        int start = page*limit;
        int end = (page+1)*limit-1;
        Map requestparamMap = new HashMap();
        List<Map<String, Object>> list = new ArrayList<>();
        if (aname!=null&&!aname.equals(""))
            requestparamMap.put("aname","%"+aname+"%");
         List<Activity> activities = activityService.getActivityList(requestparamMap);
        if (activities != null) {
            int i = 0;
            for (Activity activity : activities) {
                if (i>=start&&i<=end) {
                    int id = activity.getId();
                    String add = activity.getAdd();
                    String alx = activity.getAlx();
                    Date date = activity.getAdate();
                    String adate = String.valueOf(date.getYear() + 1900) + "年" + String.valueOf(date.getMonth() + 1) + "月" + String.valueOf(date.getDate()) + "日";
                    int ssuid = activity.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    String anamestr = activity.getAname();
                    String axx = activity.getAxx();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("aname", anamestr);
                    map.put("axx", axx);
                    map.put("ssuid", username);
                    map.put("adate", adate);
                    map.put("add", add);
                    map.put("alx", alx);
                    list.add(map);
                }
                i++;
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", activities.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了活动信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }
  /*  @RequestMapping("/selecthdjlgl")
    public JSONObject selecthdjlgl(@RequestParam(required = false)String aname, HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Integer> bjidlist = new ArrayList<>();
        List<Integer> stulist = new ArrayList<>();
      if (users.getGroupid()==2) {
            String username = users.getUsername();
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(username));
            if (teacher!=null){
                int tid = teacher.getId();
                Map classmap = new HashMap();
                classmap.put("tid",tid);
                List<Classes> classess = classesService.getClassesList(classmap);
                if (classess!=null){
                    for (Classes classes:classess){
                        int bid = classes.getId();
                       bjidlist.add(bid);
                    }
                    if (bjidlist.size()>0) {
                        Map stumap = new HashMap();
                        stumap.put("list", bjidlist);
                        List<Student> students = studentService.getStudentList(stumap);
                        if (students!=null){
                            for (Student student:students){
                                stulist.add(student.getId());
                            }
                        }
                   }
                }
            }
        }
        Map requestparamMap = new HashMap();
        List<Map<String, Object>> list = new ArrayList<>();
        if (aname!=null&&!aname.equals(""))
            requestparamMap.put("aname","%"+aname+"%");
        if (stulist.size()>0) {
            requestparamMap.put("list", stulist);
            List<Activity> activities = activityService.getActivityList(requestparamMap);
            if (activities != null) {
                for (Activity activity : activities) {
                    int id = activity.getId();
                    String add = activity.getAdd();
                    String alx = activity.getAlx();
                    Date date = activity.getAdate();
                    String adate = String.valueOf(date.getYear() + 1900) + "年" + String.valueOf(date.getMonth() + 1) + "月" + String.valueOf(date.getDate()) + "日";
                    int ssuid = activity.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    String anamestr = activity.getAname();
                    String axx = activity.getAxx();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("aname", anamestr);
                    map.put("axx", axx);
                    map.put("ssuid", username);
                    map.put("adate", adate);
                    map.put("add", add);
                    map.put("alx", alx);
                    list.add(map);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了活动信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }
*/

    /*活动记录查询*/
    @RequestMapping("/selecthdjlcx")
    public JSONObject selecthdjlcx(HttpServletRequest httpServletRequest,@RequestParam int page,@RequestParam int limit) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        String sid = users.getUsername();
        Student student=studentService.getStudentByIdcard(Integer.parseInt(sid));
        int stuid = student.getId();
        List<Activity> activities = activityService.getActivityByStudent(stuid);
        List<Map<String, Object>> list = new ArrayList<>();
        page = page-1;
        int start = page*limit;
        int end = (page+1)*limit-1;
        int i = 0;
        if (activities != null) {
            for (Activity activity : activities) {
                if (i>=start&&i<=end) {
                    int id = activity.getId();
                    String add = activity.getAdd();
                    String alx = activity.getAlx();
                    Date date = activity.getAdate();
                    String adate = String.valueOf(date.getYear() + 1900) + "年" + String.valueOf(date.getMonth() + 1) + "月" + String.valueOf(date.getDate()) + "日";
                    int ssuid = activity.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    String anamestr = activity.getAname();
                    String axx = activity.getAxx();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("aname", anamestr);
                    map.put("axx", axx);
                    map.put("ssuid", username);
                    map.put("adate", adate);
                    map.put("add", add);
                    map.put("alx", alx);
                    list.add(map);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", activities.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学号为"+sid+"的活动信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询个人信息*/
    @RequestMapping("/selectgrxxxg")
    public JSONObject selectgrxxxg(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        String tcard = users.getUsername();
        Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(tcard));
        List<Map<String, Object>> list = new ArrayList<>();
        if (teacher != null) {
                int id = teacher.getId();
                String tnamestr = teacher.getTname();
                String tsex = teacher.getTsex();
                Date date = teacher.getTbirth();
                String tbirth = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日";
                int tcardstr = teacher.getTcard();
                String tphone = teacher.getTphone();
                String tzc = teacher.getTzc();
                Map map = new HashMap();
                map.put("id", id);
                map.put("tname", tnamestr);
                map.put("tsex", tsex);
                map.put("tbirth", tbirth);
                map.put("tcard", tcardstr);
                map.put("tphone", tphone);
                map.put("tzc", tzc);
                list.add(map);
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了"+tcard+"教师信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*显示课程信息*/
    @RequestMapping("/selectkcxxgl")
    public JSONObject selectkcxxgl(@RequestParam(required = false)String kname, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (kname!=null&&!kname.equals(""))
            requestparamMap.put("kname","%"+kname+"%");
        List<Kecheng> kechengs = kechengService.getKechengList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (kechengs != null) {
            for (Kecheng kecheng : kechengs) {
                int id = kecheng.getId();
                String kclx = kecheng.getKclx();
                String kcsx = kecheng.getKcsx();
                String kcxz = kecheng.getKcxz();
                String knamestr = kecheng.getKname();
                String teacher = teacherService.getTeacherById(Integer.parseInt(kecheng.getTeacher())).getTname();
                int xf = kecheng.getXf();
                int zxs = kecheng.getZxs();
                Map map = new HashMap();
                map.put("id", id);
                map.put("kclx", kclx);
                map.put("kcsx", kcsx);
                map.put("kcxz", kcxz);
                map.put("kname", knamestr);
                map.put("teacher", teacher);
                map.put("xf", xf);
                map.put("zxs", zxs);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了课程信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看课程信息*/
    @RequestMapping("/selectkc")
    public JSONObject selectkc(HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        List<Kecheng> kechengs = kechengService.getKechengList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (kechengs != null) {
            for (Kecheng kecheng : kechengs) {
                int id = kecheng.getId();
                String knamestr = kecheng.getKname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("kname", knamestr);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了课程列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看班级信息*/
    @RequestMapping("/selectbjxxgl")
    public JSONObject selectbjxxgl(@RequestParam(required = false)String bj, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (bj!=null&&!bj.equals(""))
            requestparamMap.put("bj","%"+bj+"%");
        List<Classes> classess = classesService.getClassesList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (classess != null) {
            for (Classes classes : classess) {
                int id = classes.getId();
                String bjstr = classes.getBj();
                String zy = classes.getZy();
                String nj = classes.getNj();
                String xy = classes.getXy();
                String teacher = teacherService.getTeacherById(classes.getSstid()).getTname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("bj", bjstr);
                map.put("zy", zy);
                map.put("nj", nj);
                map.put("xy", xy);
                map.put("teacher", teacher);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了班级信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询学期信息*/
    @RequestMapping("/selectxqxxgl")
    public JSONObject selectxqxxgl(@RequestParam(required = false)String xq, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (xq!=null&&!xq.equals(""))
            requestparamMap.put("xq","%"+xq+"%");
        List<Semester> semesters = semesterService.getSemesterList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (semesters != null) {
            for (Semester semester : semesters) {
                int id = semester.getId();
                String xqstr = semester.getXq();
                String year = semester.getYear();
                Map map = new HashMap();
                map.put("id", id);
                map.put("xq", xqstr);
                map.put("year", year);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学期信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询学期信息*/
    @RequestMapping("/selectxq")
    public JSONObject selectxq(HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        List<Semester> semesters = semesterService.getSemesterList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (semesters != null) {
            for (Semester semester : semesters) {
                int id = semester.getId();
                String xqstr = semester.getXq();
                String year = semester.getYear();
                Map map = new HashMap();
                map.put("id", id);
                map.put("xq", xqstr);
                map.put("year", year);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学期列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*教师下综合成绩管理*/
    @RequestMapping("/selectzhcjgl")
    public JSONObject selectzhcjgl(@RequestParam(required = false) String name, @RequestParam(required = false) String sidstr,HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Map<String, Object>> list = new ArrayList<>();
        List<Integer> sids = new ArrayList<>();
        if (users!=null&&users.getGroupid()==2){
            String username = users.getUsername();
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(username));
            if (teacher!=null) {
                Map cmap = new HashMap();
                cmap.put("tid", teacher.getId());
                List<Classes> classess = classesService.getClassesList(cmap);
                if (classess!=null){
                    for (Classes classes :classess ){
                        List<Integer> cid = new ArrayList<>();
                        int cidtemp = classes.getId();
                        cid.add(cidtemp);
                        if (cid.size()>0){
                            Map smap = new HashMap();
                            smap.put("list",cid);
                            List<Student> students = studentService.getStudentList(smap);
                            if (students!=null){
                                for (Student student : students){
                                    int sid = student.getId();
                                    sids.add(sid);
                                }
                            }
                        }
                    }
                }
            }
        }
        Map requestparamMap = new HashMap();
        if (name!=null && !name.equals(""))
        requestparamMap.put("name","%"+name+"%");
        if (sidstr!=null && !sidstr.equals(""))
            requestparamMap.put("sid",sidstr);
        if (sids.size()>0){
            requestparamMap.put("list",sids);
            List<Zhcj> zhcjs = zhcjService.getZhcjglList(requestparamMap);
            if (zhcjs != null) {
                for (Zhcj zhcj : zhcjs) {
                    int id = zhcj.getId();
                    int ssuid = zhcj.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    int sssid = zhcj.getSssid();
                    String xq = semesterService.getSemesterById(sssid).getYear()+"--"+semesterService.getSemesterById(sssid).getXq();
                    int ztid = zhcj.getSszid();
                    String ztname = zhuangtaiService.getZhuangtaiById(ztid).getZtname();
                    String zxfjd = zhcj.getZxfjd();
                    String zhcjstr = zhcj.getZhcj();
                    String yscj = zhcj.getYscj();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("username", username);
                    map.put("xq", xq);
                    map.put("ztname", ztname);
                    map.put("zxfjd", zxfjd);
                    map.put("zhcj", zhcjstr);
                    map.put("yscj", yscj);
                    list.add(map);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了综合成绩信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*成绩分析查询综合成绩*/
    @RequestMapping("/selectzhcjglrender")
    public JSONObject selectzhcjglrender(@RequestParam String sidstr,@RequestParam String cidstr,HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Map<String, Object>> list = new ArrayList<>();
        List<Integer> sids = new ArrayList<>();
        Map requestparamMap = new HashMap();
        List<Student> students = studentService.getStudentByClasses(Integer.parseInt(cidstr));
        if (students!=null){
            for (Student student:students){
                sids.add(student.getId());
            }
        }
        if (sidstr!=null && !sidstr.equals(""))
            requestparamMap.put("sid",sidstr);
        Map renderdata = new HashMap();
        if (sids.size()>0){
            requestparamMap.put("list",sids);
            List<Zhcj> zhcjs = zhcjService.getZhcjglList(requestparamMap);
            int anum=0;
            int bnum=0;
            int cnum=0;
            int dnum=0;
            int fnum=0;
            if (zhcjs != null) {
                for (Zhcj zhcj : zhcjs) {
                    int id = zhcj.getId();
                    int ssuid = zhcj.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    int sssid = zhcj.getSssid();
                    String xq = semesterService.getSemesterById(sssid).getYear()+"--"+semesterService.getSemesterById(sssid).getXq();
                    int ztid = zhcj.getSszid();
                    String ztname = zhuangtaiService.getZhuangtaiById(ztid).getZtname();
                    String zxfjd = zhcj.getZxfjd();
                    String zhcjstr = zhcj.getZhcj();
                    String yscj = zhcj.getYscj();
                    if (Double.parseDouble(zhcj.getZhcj())>=0&&Double.parseDouble(zhcj.getZhcj())<60)
                        anum++;
                    else if (Double.parseDouble(zhcj.getZhcj())<70)
                        bnum++;
                    else if (Double.parseDouble(zhcj.getZhcj())<80)
                        cnum++;
                    else if (Double.parseDouble(zhcj.getZhcj())<90)
                        dnum++;
                    else
                        fnum++;
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("username", username);
                    map.put("xq", xq);
                    map.put("ztname", ztname);
                    map.put("zxfjd", zxfjd);
                    map.put("zhcj", zhcjstr);
                    map.put("yscj", yscj);
                    list.add(map);
                }
                String [] names= new String[]{classesService.getClassesById(Integer.parseInt(cidstr)).getBj(),"0--60分","60--70分","70--80分","80--90分","90--100分"};
                int [] nums = new int[]{0,anum,bnum,cnum,dnum,fnum};
                for (int t=0;t<6;t++){
                    Map renderdatatemp = new HashMap();
                    renderdatatemp.put("name",names[t]);
                    renderdatatemp.put("num",nums[t]);
                    renderdata.put("renderdata"+t,renderdatatemp);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        map1.put("render",renderdata);
        setLog.setlod(httpServletRequest, "查询了综合成绩信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*用户输入密码与数据库中原密码比较*/
    @RequestMapping("/getoldpass")
    public JSONObject getoldpass(@RequestParam(value = "oldpass")String oldpass,
                                         HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        oldpass = UtilPacket.Md5MD5String(oldpass);
        int code = 500;
        String msg= "账号服务器错误！";
        Users users = (Users)session.getAttribute("islogin");
        String upass = users.getUpassword();
        if (upass.equals(oldpass)){
            code = 0;
            msg = "验证成功";
        }
        else {
            code = 1;
            msg = "原密码错误！";
        }
        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("code",code);
        map.put("msg",msg);
        JSONObject json = new JSONObject(map);
        return json;
    }

    /*学生查询综合成绩*/
    @RequestMapping("/selectzhcjcx")
    public JSONObject selectzhcjcx(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        List<Map<String, Object>> list = new ArrayList<>();
        Users users = (Users) session.getAttribute("islogin");
        if(users!=null && users.getGroupid()==3) {
            Student student = studentService.getStudentByIdcard(Integer.parseInt(users.getUsername()));
            if (student != null) {
               int sid = student.getId();
                Map requestparamMap = new HashMap();
               requestparamMap.put("ssuid",sid);
                List<Zhcj> zhcjs = zhcjService.getZhcjList(requestparamMap);
                if (zhcjs != null) {
                    for (Zhcj zhcj : zhcjs) {
                        int id = zhcj.getId();
                        int ssuid = zhcj.getSsuid();
                        String username = studentService.getStudentById(ssuid).getSname();
                        int sssid = zhcj.getSssid();
                        String xq = semesterService.getSemesterById(sssid).getYear() + "--" + semesterService.getSemesterById(sssid).getXq();
                        int ztid = zhcj.getSszid();
                        String ztname = zhuangtaiService.getZhuangtaiById(ztid).getZtname();
                        String zxfjd = zhcj.getZxfjd();
                        String zhcjstr = zhcj.getZhcj();
                        String yscj = zhcj.getYscj();
                        Map map = new HashMap();
                        map.put("id", id);
                        map.put("username", username);
                        map.put("xq", xq);
                        map.put("ztname", ztname);
                        map.put("zxfjd", zxfjd);
                        map.put("zhcj", zhcjstr);
                        map.put("yscj", yscj);
                        list.add(map);
                    }
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学号为"+users.getUsername()+"的综合成绩信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*学生查询综合成绩并异议申报*/
    @RequestMapping("/selectxsyysb")
    public JSONObject selectxsyysb(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        List<Map<String, Object>> list = new ArrayList<>();
        Users users = (Users) session.getAttribute("islogin");
        if (users!=null&&users.getGroupid()==3){
        Student student = studentService.getStudentByIdcard(Integer.parseInt(users.getUsername()));
        if (student!=null){
            int sid = student.getId();
            Map requestparamMap = new HashMap();
            requestparamMap.put("ztid",1);
            requestparamMap.put("ssuid",sid);
            List<Zhcj> zhcjs = zhcjService.getZhcjList(requestparamMap);
            if (zhcjs != null) {
                for (Zhcj zhcj : zhcjs) {
                    int id = zhcj.getId();
                    int ssuid = zhcj.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    int sssid = zhcj.getSssid();
                    String xq = semesterService.getSemesterById(sssid).getYear()+"--"+semesterService.getSemesterById(sssid).getXq();
                    int ztid = zhcj.getSszid();
                    String ztname = zhuangtaiService.getZhuangtaiById(ztid).getZtname();
                    String zxfjd = zhcj.getZxfjd();
                    String zhcjstr = zhcj.getZhcj();
                    String yscj = zhcj.getYscj();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("username", username);
                    map.put("xq", xq);
                    map.put("ztname", ztname);
                    map.put("zxfjd", zxfjd);
                    map.put("zhcj", zhcjstr);
                    map.put("yscj", yscj);
                    list.add(map);
                }
            }
             }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了有异议的综合成绩信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*教师查询学生异议申报*/
    @RequestMapping("/selectxsyycl")
    public JSONObject selectxsyycl(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Map<String, Object>> list = new ArrayList<>();
        List<Integer> sids = new ArrayList<>();
        if (users!=null&&users.getGroupid()==2){
            String username = users.getUsername();
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(username));
            if (teacher!=null) {
                Map cmap = new HashMap();
                cmap.put("tid", teacher.getId());
                List<Classes> classess = classesService.getClassesList(cmap);
                if (classess!=null){
                    for (Classes classes :classess ){
                        List<Integer> cid = new ArrayList<>();
                        int cidtemp = classes.getId();
                        cid.add(cidtemp);
                        if (cid.size()>0){
                            Map smap = new HashMap();
                            smap.put("list",cid);
                            List<Student> students = studentService.getStudentList(smap);
                            if (students!=null){
                                for (Student student : students){
                                    int sid = student.getId();
                                    sids.add(sid);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (sids.size()>0){
            Map requestparamMap = new HashMap();
            requestparamMap.put("ztid",2);
            requestparamMap.put("list",sids);
            List<Zhcj> zhcjs = zhcjService.getZhcjList(requestparamMap);
            if (zhcjs != null) {
                for (Zhcj zhcj : zhcjs) {
                    int id = zhcj.getId();
                    int ssuid = zhcj.getSsuid();
                    String username = studentService.getStudentById(ssuid).getSname();
                    int sssid = zhcj.getSssid();
                    String xq = semesterService.getSemesterById(sssid).getYear()+"--"+semesterService.getSemesterById(sssid).getXq();
                    int ztid = zhcj.getSszid();
                    String ztname = zhuangtaiService.getZhuangtaiById(ztid).getZtname();
                    String zxfjd = zhcj.getZxfjd();
                    String zhcjstr = zhcj.getZhcj();
                    String yscj = zhcj.getYscj();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("username", username);
                    map.put("xq", xq);
                    map.put("ztname", ztname);
                    map.put("zxfjd", zxfjd);
                    map.put("zhcj", zhcjstr);
                    map.put("yscj", yscj);
                    list.add(map);
                }
            }
        }

        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了有异议的综合成绩信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询状态信息*/
    @RequestMapping("/selectztxxgl")
    public JSONObject selectztxxgl(@RequestParam(required = false)String ztname, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (ztname!=null&&!ztname.equals(""))
            requestparamMap.put("ztname","%"+ztname+"%");
        List<Zhuangtai> zhuangtais = zhuangtaiService.getZhuangtaiList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (zhuangtais != null) {
            for (Zhuangtai zhuangtai : zhuangtais) {
                int id = zhuangtai.getId();
                String ztnamestr = zhuangtai.getZtname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("ztname", ztnamestr);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了状态信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询用户账号*/
    @RequestMapping("/selectyhzhgl")
    public JSONObject selectyhzhgl(@RequestParam(required = false)String username,HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (username!=null&&!username.equals(""))
            requestparamMap.put("username","%"+username+"%");
        List<Users> userss = usersService.getuserList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (userss != null) {
            for (Users users : userss) {
                int id = users.getId();
                String usernamestr = users.getUsername();
                int gid = users.getGroupid();
                String groupstr = groupinfoService.getGroupinfoById(gid).getGroupname();
                Date date = users.getRegtime();
                String hour = date.getHours()>9?String.valueOf(date.getHours()):0+String.valueOf(date.getHours());
                String minute = date.getMinutes()>9?String.valueOf(date.getMinutes()):0+String.valueOf(date.getMinutes());
                String second = date.getSeconds()>9?String.valueOf(date.getSeconds()):0+String.valueOf(date.getSeconds());
                String regtime = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日--"+hour+":"+minute+":"+second;
                Map map = new HashMap();
                map.put("id", id);
                map.put("username", usernamestr);
                map.put("groupstr", groupstr);
                map.put("regtime", regtime);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了用户信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*管理员查询学生信息*/
    @RequestMapping("/selectxsxxgl")
    public JSONObject selectxsxxgl(@RequestParam(required = false)String sname,@RequestParam(required = false) String idcard, HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        if (sname!=null&&!sname.equals(""))
            requestparamMap.put("sname","%"+sname+"%");
        if (idcard!=null&&!idcard.equals(""))
            requestparamMap.put("idcard","%"+idcard+"%");
        List<Student> students = studentService.getStudentList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (students != null) {
            for (Student student : students) {
                int id = student.getId();
                String snamestr = student.getSname();
                int xuehao = student.getXuehao();
                String ssex = student.getSsex();
                Date date = student.getScsny();
                String scsny = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日";
                int bid = student.getSscid();
                Classes classes = classesService.getClassesById(bid);
                String ssbj = classes.getBj();
                String sszy = classes.getZy();
                String sphone = student.getSphone();
                Map map = new HashMap();
                map.put("id", id);
                map.put("sname", snamestr);
                map.put("xuehao", xuehao);
                map.put("ssex", ssex);
                map.put("sszy", sszy);
                map.put("ssbj", ssbj);
                map.put("scsny", scsny);
                map.put("sphone", sphone);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学生信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*教师查询学生信息*/
    @RequestMapping("/selectxsxxgljs")
    public JSONObject selectxsxxgljs(@RequestParam(required = false)String sname,@RequestParam(required = false) String idcard, HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Integer> bjidlist = new ArrayList<>();
        if (users.getGroupid()==2) {
            String username = users.getUsername();
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(username));
            if (teacher!=null){
                int tid = teacher.getId();
                Map classmap = new HashMap();
                classmap.put("tid",tid);
                List<Classes> classess = classesService.getClassesList(classmap);
                if (classess!=null){
                    for (Classes classes:classess){
                        int bid = classes.getId();
                        bjidlist.add(bid);
                    }
                }
            }
        }
        List<Map<String, Object>> list = new ArrayList<>();
        Map requestparamMap = new HashMap();
        if (sname!=null&&!sname.equals(""))
            requestparamMap.put("sname","%"+sname+"%");
        if (idcard!=null&&!idcard.equals(""))
            requestparamMap.put("idcard","%"+idcard+"%");
        if (bjidlist.size()>0) {
            requestparamMap.put("list", bjidlist);
            List<Student> students = studentService.getStudentList(requestparamMap);
            if (students != null) {
                for (Student student : students) {
                    int id = student.getId();
                    String snamestr = student.getSname();
                    int xuehao = student.getXuehao();
                    String ssex = student.getSsex();
                    Date date = student.getScsny();
                    String scsny = String.valueOf(date.getYear() + 1900) + "年" + String.valueOf(date.getMonth() + 1) + "月" + String.valueOf(date.getDate()) + "日";
                    int bid = student.getSscid();
                    Classes classes = classesService.getClassesById(bid);
                    String ssbj = classes.getBj();
                    String sszy = classes.getZy();
                    String sphone = student.getSphone();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("sname", snamestr);
                    map.put("xuehao", xuehao);
                    map.put("ssex", ssex);
                    map.put("sszy", sszy);
                    map.put("ssbj", ssbj);
                    map.put("scsny", scsny);
                    map.put("sphone", sphone);
                    list.add(map);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学生信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*学生修改个人信息*/
    @RequestMapping("/selectgrxxxgxs")
    public JSONObject selectgrxxxgxs(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        String sid = users.getUsername();
        Student student = studentService.getStudentByIdcard(Integer.parseInt(sid));
        List<Map<String, Object>> list = new ArrayList<>();
        if (student != null) {
                int id = student.getId();
                String snamestr = student.getSname();
                int xuehao = student.getXuehao();
                String ssex = student.getSsex();
                Date date = student.getScsny();
                String scsny = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日";
                int bid = student.getSscid();
                Classes classes = classesService.getClassesById(bid);
                String ssbj = classes.getBj();
                String sszy = classes.getZy();
                String sphone = student.getSphone();
                Map map = new HashMap();
                map.put("id", id);
                map.put("sname", snamestr);
                map.put("xuehao", xuehao);
                map.put("ssex", ssex);
                map.put("sszy", sszy);
                map.put("ssbj", ssbj);
                map.put("scsny", scsny);
                map.put("sphone", sphone);
                list.add(map);
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了"+sid+"学生信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*学生成绩管理*/
    @RequestMapping("/selectxscjgl")
    public JSONObject selectxscjgl(HttpServletRequest httpServletRequest,@RequestParam(required = false) String idcard,@RequestParam(required = false) Integer kid,@RequestParam(required = false) Integer sid) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        int isnull = 0;
        Map requestparamMap = new HashMap();
        if (idcard != null && !idcard.equals("")) {
            Student studentpa = studentService.getStudentByIdcard(Integer.parseInt(idcard));
            if (studentpa!=null){
                requestparamMap.put("st",studentpa.getId());
            }
            else {
                isnull=1;
            }
        }
        requestparamMap.put("sskid",kid);
        requestparamMap.put("sssid",sid);
        List<Map<String, Object>> list = new ArrayList<>();
        if (users!=null&&isnull!=1){
            if (users.getGroupid()==2){
               String tusername = users.getUsername();
               Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(tusername));
               if (teacher!=null){
                   int tid = teacher.getId();
                   Map cmap = new HashMap();
                   cmap.put("tid",tid);
                   List<Classes> classess = classesService.getClassesList(cmap);
                   List<Integer> cid = new ArrayList<>();
                   if (classess!=null){
                       for (Classes classes:classess){
                           cid.add(classes.getId());
                       }
                   }
                   List<Integer> sids = new ArrayList<>();
                   Map smap = new HashMap();
                   if (cid.size()>0) {
                       smap.put("list", cid);
                       List<Student> slist = studentService.getStudentList(smap);
                       if (slist!=null){
                           for (Student student:slist){
                               sids.add(student.getId());
                           }
                       }
                   }
                   if (sids.size()>0){
                       requestparamMap.put("list",sids);
                       List<Grade> grades = gradeService.getGradeList(requestparamMap);
                       if (grades != null) {
                           for (Grade grade : grades) {
                               int id = grade.getId();
                               int sidstr = grade.getSt();
                               String st = studentService.getStudentById(sidstr).getSname();
                               int kidstr = grade.getSskid();
                               String sskid = kechengService.getKechengById(kidstr).getKname();
                               int seid = grade.getSssid();
                               String sssid = semesterService.getSemesterById(seid).getYear()+"--"+semesterService.getSemesterById(seid).getXq();
                               String gradestr = grade.getGrade();
                               int xf = kechengService.getKechengById(kidstr).getXf();
                               int zxs = kechengService.getKechengById(kidstr).getZxs();
                               String khfs = grade.getKhfs();
                               String ksxz = grade.getKsxz();
                               String xfjd = grade.getXfjd();
                               DecimalFormat df = new DecimalFormat("#.00");
                               Map map = new HashMap();
                               map.put("id", id);
                               map.put("st", st);
                               map.put("sskid", sskid);
                               map.put("sssid", sssid);
                               map.put("grade", gradestr);
                               map.put("xf", xf);
                               map.put("zxs", zxs);
                               map.put("khfs", khfs);
                               map.put("ksxz", ksxz);
                               map.put("xfjd", df.format(Double.parseDouble(xfjd)));
                               list.add(map);
                           }
                       }
                   }
               }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学生成绩数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*学生查询成绩*/
    @RequestMapping("/selectcjcx")
    public JSONObject selectcjcx(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        Student student = studentService.getStudentByIdcard(Integer.parseInt(users.getUsername()));
        Map requestparamMap = new HashMap();
        requestparamMap.put("st", student.getId());
        List<Grade> grades = gradeService.getGradeList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (grades != null) {
            for (Grade grade : grades) {
                int id = grade.getId();
                int sid = grade.getSt();
                String st = studentService.getStudentById(sid).getSname();
                int kid = grade.getSskid();
                String sskid = kechengService.getKechengById(kid).getKname();
                int seid = grade.getSssid();
                String sssid = semesterService.getSemesterById(seid).getYear()+"--"+semesterService.getSemesterById(seid).getXq();
                String gradestr = grade.getGrade();
                int xf = kechengService.getKechengById(kid).getXf();
                int zxs = kechengService.getKechengById(kid).getZxs();
                String khfs = grade.getKhfs();
                String ksxz = grade.getKsxz();
                String xfjd = grade.getXfjd();
                Map map = new HashMap();
                map.put("id", id);
                map.put("st", st);
                map.put("sskid", sskid);
                map.put("sssid", sssid);
                map.put("grade", gradestr);
                map.put("xf", xf);
                map.put("zxs", zxs);
                map.put("khfs", khfs);
                map.put("ksxz", ksxz);
                map.put("xfjd", xfjd);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学生成绩数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看课程比例*/
    @RequestMapping("/selectkcbl")
    public JSONObject selectkcbl(HttpServletRequest httpServletRequest) {
        List<Kcbl> kcbls = kcblService.getkcbllist();
        List<Map<String, Object>> list = new ArrayList<>();
        if (kcbls != null) {
            for (Kcbl kcbl : kcbls) {
                int id = kcbl.getId();
                String kname = kcbl.getKname();
                String bl = kcbl.getBl();
                Map map = new HashMap();
                map.put("id", id);
                map.put("kname", kname);
                map.put("bl", bl);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了课程比例数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*推荐学生学号*/
    @RequestMapping("/selectxslast")
    public JSONObject selectxslast(HttpServletRequest httpServletRequest) {
        Student student = studentService.getStudentBylast();
        List<Map<String, Object>> list = new ArrayList<>();
        int idcard = student.getXuehao();
        Map map = new HashMap();
        map.put("idcard", idcard+1);
        list.add(map);
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了最后一条学生数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询班级列表*/
    @RequestMapping("/selectbj")
    public JSONObject selectbj(HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        Users users = (Users) httpServletRequest.getSession().getAttribute("islogin");
        if (users!=null&&users.getGroupid()==2){
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(users.getUsername()));
            if (teacher!=null){
                int tid = teacher.getId();
                requestparamMap.put("tid",tid);
            }
        }
        List<Classes> classess = classesService.getClassesList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (classess != null) {
            for (Classes classes : classess) {
                int id = classes.getId();
                String bname = classes.getBj();
                Map map = new HashMap();
                map.put("id", id);
                map.put("bname", bname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了班级列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询学生*/
    @RequestMapping("/selectxs")
    public JSONObject selectxs(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        Users users = (Users) session.getAttribute("islogin");
        List<Map<String, Object>> list = new ArrayList<>();
        List<Integer> sids = new ArrayList<>();
        if (users!=null&&users.getGroupid()==2){
            String username = users.getUsername();
            Teacher teacher = teacherService.getTeacherBytcard(Integer.parseInt(username));
            if (teacher!=null) {
                Map cmap = new HashMap();
                cmap.put("tid", teacher.getId());
                List<Classes> classess = classesService.getClassesList(cmap);
                if (classess!=null){
                    for (Classes classes :classess ){
                        List<Integer> cid = new ArrayList<>();
                        int cidtemp = classes.getId();
                        cid.add(cidtemp);
                        if (cid.size()>0){
                            Map smap = new HashMap();
                            smap.put("list",cid);
                            List<Student> students = studentService.getStudentList(smap);
                            if (students!=null){
                                for (Student student : students){
                                    int sid = student.getId();
                                    sids.add(sid);
                                }
                            }
                        }
                    }
                }
            }
        }
        if (sids.size()>0){
            Map requestparamMap = new HashMap();
            requestparamMap.put("list2",sids);
            List<Student> students = studentService.getStudentList(requestparamMap);
            if (students != null) {
                for (Student student : students) {
                    int id = student.getId();
                    String sname = student.getSname();
                    int xuehao = student.getXuehao();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("sname", sname);
                    map.put("xuehao", xuehao);
                    list.add(map);
                }
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了学生列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看教师*/
    @RequestMapping("/selectjs")
    public JSONObject selectjs(HttpServletRequest httpServletRequest) {
        Map requestparamMap = new HashMap();
        List<Teacher> teachers = teacherService.getTeacherList(requestparamMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (teachers != null) {
            for (Teacher teacher : teachers) {
                int id = teacher.getId();
                String tname = teacher.getTname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("tname", tname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了教师列表数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询教师工号*/
    @RequestMapping("/selectjslast")
    public JSONObject selectjslast(HttpServletRequest httpServletRequest) {
        Teacher teacher = teacherService.getteacherlast();
        List<Map<String, Object>> list = new ArrayList<>();
        int idcard = teacher.getTcard();
        Map map = new HashMap();
        map.put("idcard", idcard+1);
        list.add(map);
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了最后一条教师数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看系统日志*/
    @RequestMapping("/selectxtrzgl")
    public Map<String, Object> selectxtrzgl(HttpServletRequest httpServletRequest, @RequestParam(value = "page") int page,@RequestParam(value = "limit") int limit) {
        page = page-1;
        int start = page*limit;
        int end = (page+1)*limit-1;
        List<Log> logs = logService.getlogList();
        int datacount = logs.size();
        int i = 0;
        List<Map<String, Object>> list = new ArrayList<>();
        if (logs != null) {
            for (Log log : logs) {
                if (i>=start&&i<=end){
                    int id = log.getId();
                    String cz = log.getCz();
                    int czr = log.getCzr();
                    Date date = log.getTime();
                    String hour = date.getHours()>9?String.valueOf(date.getHours()):0+String.valueOf(date.getHours());
                    String minute = date.getMinutes()>9?String.valueOf(date.getMinutes()):0+String.valueOf(date.getMinutes());
                    String second = date.getSeconds()>9?String.valueOf(date.getSeconds()):0+String.valueOf(date.getSeconds());
                    String timestr = String.valueOf(date.getYear()+1900)+"年"+String.valueOf(date.getMonth()+1)+"月"+String.valueOf(date.getDate())+"日--"+hour+":"+minute+":"+second;
                    String czrstr=usersService.selectByPrimaryKey(czr).getUsername();
                    Map map = new HashMap();
                    map.put("id", id);
                    map.put("cz", cz);
                    map.put("czr", czrstr);
                    map.put("time", timestr);
                    list.add(map);
                }
                i++;
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", datacount);
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了全部系统日志信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询父菜单*/
    @RequestMapping("/selectfcd2")
    public JSONObject selectfcd2(HttpServletRequest httpServletRequest) {
        List<Menu> menus = menuService.getfdmmenuList();
        List<Map<String, Object>> list = new ArrayList<>();
        if (menus != null) {
            for (Menu menu : menus) {
                int id = menu.getId();
                String menuname = menu.getMenuname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("menuname", menuname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了父菜单信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查看用户组信息*/
    @RequestMapping("/selectyhzxxgl")
    public JSONObject selectyhzxxgl(@RequestParam(required = false) String name, HttpServletRequest httpServletRequest) {
        Map paramMap = new HashMap();
        if (name!=null && !name.equals(""))
            paramMap.put("name","%"+name+"%");
        List<Groupinfo> groupinfos = groupinfoService.getGroupinfoList(paramMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (groupinfos != null) {
            for (Groupinfo groupinfo : groupinfos) {
                int id = groupinfo.getId();
                String qx = groupinfo.getQx();
                String groupname = groupinfo.getGroupname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("qx", qx);
                map.put("groupname", groupname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了全部用户组信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

    /*查询菜单*/
    @RequestMapping("/selectcdgl")
    public JSONObject selectcdgl(HttpServletRequest httpServletRequest) {
        List<Menu> menus = menuService.getmenuList();
        List<Map<String, Object>> list = new ArrayList<>();
        if (menus != null) {
            for (Menu menu : menus) {
                int id = menu.getId();
                String fdm = null;
                if(menu.getFdm()!=null&&menu.getFdm()!="") {
                    fdm = menuService.selectByPrimaryKey(Integer.parseInt(menu.getFdm())).getMenuname();
                }
                String menulink = menu.getMenulink();
                String menuname = menu.getMenuname();
                Map map = new HashMap();
                map.put("id", id);
                map.put("fdm", fdm);
                map.put("menulink", menulink);
                map.put("menuname", menuname);
                list.add(map);
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("code", 0);
        map1.put("msg", "ok");
        map1.put("count", list.size());
        map1.put("data", list);
        setLog.setlod(httpServletRequest, "查询了全部菜单信息数据",logService);
        JSONObject json = new JSONObject(map1);
        return json;
    }

}
